//
//  KSCheckInboundViewController.swift
//  Supermarket
//
//  Created by liuxm on 2017/9/28.
//  Copyright © 2017年 kushao. All rights reserved.
//

import UIKit

/// 验收入库
class KSCheckInboundViewController: KSBaseViewController {

    @IBOutlet weak var tableView: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.title = "验收入库"
        
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.tableView.backgroundColor = UIColor.colorWithHexString(hex: "#f4f5f7")
        
        let nib = UINib(nibName: "KSCheckInboundTableViewCell", bundle: nil)
        self.tableView.register(nib, forCellReuseIdentifier: "KSCheckInboundTableViewCell")
        
        let totalNib = UINib(nibName: "KSTitleAndValueTableViewCell", bundle: nil)
        self.tableView.register(totalNib, forCellReuseIdentifier: "KSTitleAndValueTableViewCell")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

extension KSCheckInboundViewController: UITableViewDelegate, UITableViewDataSource {
    
    // UITableViewDataSource
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 3
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        var num = 1
        if section == 2 {
            num = 4
        }
        
        return num
    }
    
    
    // UITableViewDelegate
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 10
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        var height = 175
        if indexPath.section == 2 {
            height = 44
        }
        return CGFloat(height)
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.01
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.section == 2 {
            let cell = tableView.dequeueReusableCell(withIdentifier: "KSTitleAndValueTableViewCell", for: indexPath) as! KSTitleAndValueTableViewCell
            
            switch indexPath.row {
            case 0:
            cell.titleLabel.text = "进货总数"
            cell.valueLabel.text = "66"
            case 1:
            cell.titleLabel.text = "实际入库总数"
            cell.valueLabel.text = "60"
            case 2:
            cell.titleLabel.text = "总计"
            cell.valueLabel.text = "¥213.00"
            case 3:
            cell.titleLabel.text = "入库金额"
            cell.valueLabel.text = "¥213.00"
            default:
                break
            }
            
            return cell
        }
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "KSCheckInboundTableViewCell", for: indexPath) as! KSCheckInboundTableViewCell
        
        return cell
    }
    
}
